/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core.model;

import core.io.Session;
import core.log.Monitor;
import java.util.Hashtable;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author ASUS_2
 */
public class SessionPool {

    private ConcurrentHashMap<Integer, Session> pool;

    public SessionPool() {
        pool = new ConcurrentHashMap<>();
    }

    public void put(Session session) {
        int id = session.getUserInfor().getUserID();
        if (!pool.containsKey(id)) {
            pool.put(id, session);
        }
    }

    public void remove(int id) {
        pool.remove(id);
    }

    public Session getSession(int id) {
        Session session = null;
        try {
            if (!pool.containsKey(id)) {
                pool.get(id);
            }
        } catch (Exception ex) {
            Monitor.error("getSession: ", ex);
        } finally {
            return session;
        }
    }
}
